package com.yyzw.activiti.modeler.util;

import java.security.MessageDigest;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */

public class EncryptUtil {
    public EncryptUtil() {
    }

    static public String EncryptString(String in) throws Exception {
        if (in == null || "".equals(in)) {
            return "";
        }
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(in.trim().getBytes()); //

        byte[] b = md5.digest();
        return byte2hex(b);


    }

    /**
     * 字节转换成十六进制字符串
     */
    static public String byte2hex(byte[] b) {
        String hs = "";
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = (Integer.toHexString(b[n] & 0XFF));
            if (stmp.length() == 1) {
                hs = hs + "0" + stmp;
            } else {
                hs = hs + stmp;
            }
        }
        return hs;
    }
  
 /* public static void main(String args[]){
      String pwd = "1111";
	  String encryptPwd = EncryptUtil.EncryptString(pwd);
	  System.out.println(encryptPwd);
	  encryptPwd = EncryptUtil.EncryptString(encryptPwd);
	  System.out.println(encryptPwd);
  }*/
}
